package com.citrix.gs.util.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Config {
    
    private static Config instance = null;
    private Properties prop = new Properties();
    
    public static Config me() {
        
        if(instance == null) {
            try {
                instance = new Config();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        return instance;
    }
    
    protected Config() throws IOException {
        
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("common-config.properties");
        prop.load(in);
    }
    
    public String getProperty(String key) {
        return prop.getProperty(key);
    }
    
    public String getProperty(String key, String defaultValue) {
        return prop.getProperty(key, defaultValue);
    }
    
    public CIInfo getTestCI(){

       return new CIInfo(prop.getProperty("test.jenkins.host"),
               prop.getProperty("test.jenkins.port"),
               prop.getProperty("test.jenkins.username"),
               prop.getProperty("test.jenkins.password")).setType(CIType.test);
    }
    
    public String getTestToolDir(){
        return getProperty("test.tool.dir", "//localization/LocEngineering/LocEngg-Tools/BeaconToolset_TEST");
    }
    
    public String getProdToolDir() {
        return getProperty("prod.tool.dir", "//localization/LocEngineering/LocEngg-Tools/BeaconToolset");
    }
    
    public CIInfo getProdCI(){
        return new CIInfo(prop.getProperty("prod.jenkins.host"),
                prop.getProperty("prod.jenkins.port"),
                prop.getProperty("prod.jenkins.username"),
                prop.getProperty("prod.jenkins.password")).setType(CIType.prod);
    }
    
    public String getTestBeaconRestURL(){
        return getProperty("test.beacon.rest");
    }
    
    public String getTestMongodbURL() {
        return getProperty("test.mongodb.url");
    }
    
    public String getProdBeaconRestURL(){
        return getProperty("prod.beacon.rest");
    }
    
    public String getProdMongodbURL() {
        return getProperty("prod.mongodb.url");
    }
    
    public String getRepoConfigLocalPath(){
        return getProperty("repo.config");
    }
    
    public String getRepoConfigPerforcePath(){
        return getProperty("repo.config.perforce", "//localization/LocEngineering/LocEngg-Tools/WebPortal/toolset/DailyJobs/jobs/beacon/repo_check/config_repro_check.xml");
    }
}
